package com.hrt.datasender.process.strategy.hj212;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import com.btcode.db.result.Row;
import com.hrt.datasender.datadao.model.BcSendPlatformModel;
import com.hrt.datasender.datadao.service.BdSendRecordService;
import com.hrt.datasender.datastorage.StorageDataType;
import com.hrt.datasender.process.strategy.hj212.util.DataType;

public class Com2051NFBProcess extends ProcessStrategyMonitorData {

    @Override
    public Object packet(List<Row> data, BcSendPlatformModel sendPlatform) {
        final long timeDiffer = 10000;
        String msg = getCommandPacket(sendPlatform, getDataType(), data, timeDiffer);
        // 更新数据时间
        StorageDataType dataType = StorageDataType.MINUTES;
        String ip = sendPlatform.getIp();
        String port = sendPlatform.getPort();
        HashMap<String, String> cpValueMap = MessagePraser.getCpValue(msg);
        String datatime = cpValueMap.get("DataTime");
        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
        Date dateTime;
        try {
            dateTime = sf.parse(datatime);
            BdSendRecordService.getInstance().updateLastSendDate(dataType, ip, port, dateTime);
        }
        catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return msg;
    }

    @Override
    public String getStrategyName() {
        return "分钟数据解析(无反馈)";
    }

    @Override
    public DataType getDataType() {
        return DataType.minute;
    }

    @Override
    public String getCommandId() {
        return "2051";
    }

}
